<template>
  <el-dialog
    :visible.sync="callVisible"
    title="通话"
    custom-class="video-dialog"
    :close-on-click-modal="false"
    width="600px"
    @closed="deleteCall"
  >
    <div v-if="callStatus === 61443">
      <span style="color: #fff">被叫或呼叫者被占用, 请稍后再试！</span>
    </div>
    <div v-if="callStatus === 0">
      <span style="color: #fff">
        <i class="el-icon-phone-outline" style="font-size: 36px"></i>&nbsp;&nbsp;正在呼叫...
      </span>
    </div>
    <div v-if="callStatus === 100">
      <span style="color: #fff">token失效！</span>
    </div>
    <div v-if="callStatus === 'oxFoo3'">
      <span style="color: #fff">通话中！</span>
    </div>
  </el-dialog>
</template>
<script>
import { voiceCall, voiceCallHangUp } from '@/api/ummarize';
export default {
  data () {
    return {
      callVisible: false,
      callStatus: null,
    }
  },
  methods: {
    call({name, phone}) {
      this.$confirm(`呼叫 ${name} 电话：${phone}， 是否继续？`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        cancelButtonClass: 'el-button--text',
        confirmButtonClass: 'el-button--text',
        type: 'warning',
      }).then(() => {
        voiceCall({ phoneNumber: phone }).then((res) => {
          const { data, success } = res;
          if (success) {
            this.callStatus = data.status.code;
            this.callVisible = true;
            if (data.status && data.status.code === 61443) {
              this.$message.warning('被叫或呼叫者被占用, 请稍后再试！');
            } else {
              this.$message.success('拨号中，请稍候！');
            }
          }
        });
      })
      .catch(() => {});
    },
    deleteCall() {
      voiceCallHangUp().then(() => {
        this.$message.success('语音电话挂断成功');
      });
    }
  }
}
</script>